﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using QLTV.Public;

namespace QLTV.DAL
{
    public class SachDAL
    {
        ConnectionData connect;
        public DataTable Sach_Load()
        {
            try
            {
                connect = new ConnectionData();
                return connect.GetData("Sach_Load");
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public int nhapSach(SachDTO sDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 3;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@mas";
                value[0] = sDTO.MaSach;
                name[1] = "@mads";
                value[1] = sDTO.MaDS;
                name[2] = "@tt";
                value[2] = sDTO.TinhTrang;

                return connect.UpdateData("Sach_InsertUpdate", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public int Sach_Xoa(SachDTO sDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@mas";
                value[0] = sDTO.MaSach;
                return connect.UpdateData("Sach_Xoa", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable TimTheoTen(SachDTO sDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@search";
                value[0] = sDTO.MaDS;
                return connect.GetData("Sach_TimTheoTen", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable LoadDuLieuCotMaSach(SachDTO sDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparapater = 1;
                string[] name = new string[Nparapater];
                object[] value = new object[Nparapater];
                name[0] = "@mas";
                value[0] = sDTO.MaSach;
                return connect.GetData("Sach_LoadDuLieuCotMaSach", name, value, Nparapater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }

    }
    
}
